package com.sandasai.action.admin;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sandasai.service.AdminManager;
import com.sandasai.vo.PageBean;
import com.sandasai.vo.UserBean;
@Controller
@Scope("prototype")
public class AddTeacherAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Resource
	AdminManager adminManager;
	private String username;
	private String password;
	private String email;
	private int page;
	private PageBean pageBean;
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return
	 */
	public String execute() throws Exception{
		UserBean userBean = new UserBean();
		userBean.setUsername(username);
		userBean.setEmail(email);
		userBean.setPassword(password);
		if(adminManager.addTeacher(userBean)) {
			ActionContext ctx = ActionContext.getContext();
			pageBean = adminManager.queryForPageTeach(10, page);
			ctx.put("message", "添加老师账户成功！");
			return SUCCESS;
		}else {
			ActionContext ctx = ActionContext.getContext();
			ctx.put("message", "添加老师账户失败！");
			return ERROR;
		}
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public PageBean getPageBean() {
		return pageBean;
	}

	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}
}